﻿function HiLightButton(btnName)
{
	var tbl = $get('tbl' + btnName);
	if (tbl == null)
		return;
	tbl.rows[1].cells[0].className = tbl.rows[1].cells[0].className.replace("Up", "Down");
	tbl.rows[1].cells[1].className = tbl.rows[1].cells[1].className.replace("Up", "Down");
	tbl.rows[1].cells[2].className = tbl.rows[1].cells[2].className.replace("Up", "Down");
}

function RestoreButton(btnName)
{
	var tbl = $get('tbl' + btnName);
	if (tbl == null)
		return;
	tbl.rows[1].cells[0].className = tbl.rows[1].cells[0].className.replace("Down", "Up");
	tbl.rows[1].cells[1].className = tbl.rows[1].cells[1].className.replace("Down", "Up");
	tbl.rows[1].cells[2].className = tbl.rows[1].cells[2].className.replace("Down", "Up");
}

function SetButtonText(btnName, strText, strTitle)
{
	if ($get('tbl' + btnName) == null)
		return;
	if (strTitle == null)
		strTitle = strText;
	$get('tbl' + btnName).rows[1].cells[1].innerHTML = strText;
	$get('tbl' + btnName).title = strTitle;
}

function GetButtonText(btnName)
{
	if ($get('tbl' + btnName) != null)
		return $get('tbl' + btnName).rows[1].cells[1].innerHTML;
	else
		return "";
}

function SetButtonVisible(btnName, bVisible)
{
	var tbl = $get('tbl' + btnName);
	if (tbl == null)
		return;
	if ((bVisible && tbl.style.display == "inline") || (!bVisible && tbl.style.display == "none"))
		return;	// nothing to do!
	tbl.style.display = (bVisible ? "inline" : "none");
}

function GetButtonEnabled(btnName)
{
	var tbl = $get('tbl' + btnName);
	if (tbl == null)
		return false;
	return (tbl.rows[1].cells[0].className.indexOf("Disabled") == -1);
}

function SetButtonEnabled(btnName, bEnabled)
{
	var tbl = $get('tbl' + btnName);
	if (tbl == null)
		return;
	var btn = $get(btnName + '_btn');
	if (bEnabled)
	{
		if (tbl.rows[1].cells[0].className.indexOf("Disabled") != -1)
		{
			tbl.rows[1].cells[0].className = tbl.rows[1].cells[0].className.substr(0, tbl.rows[1].cells[0].className.length - 8);
			tbl.rows[1].cells[1].className = tbl.rows[1].cells[1].className.substr(0, tbl.rows[1].cells[1].className.length - 8);
			tbl.rows[1].cells[2].className = tbl.rows[1].cells[2].className.substr(0, tbl.rows[1].cells[2].className.length - 8);
			btn.onclick = new Function(btn.getAttribute("DoClick"));
			tbl.onclick = new Function(tbl.getAttribute("DoClick"));
			tbl.onmouseover = new Function(tbl.getAttribute("DoMouseOver"));
			tbl.onmouseout = new Function(tbl.getAttribute("DoMouseOut"));
		}
	}
	else
	{
		if (tbl.rows[1].cells[0].className.indexOf("Disabled") == -1)
		{
			tbl.rows[1].cells[0].className += "Disabled";
			tbl.rows[1].cells[1].className += "Disabled";
			tbl.rows[1].cells[2].className += "Disabled";
			btn.onclick = new Function("event.returnValue = false;");
			tbl.onclick = null;
			tbl.onmouseover = null;
			tbl.onmouseout = null;
			RestoreButton(btnName);
		}
	}
}
